package com.ruoyi.web.controller.devicedata;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.web.pojo.dto.devicedata.DeviceFactorCountData;
import com.ruoyi.web.pojo.request.devicedata.DeviceRainCountRequest;
import com.ruoyi.web.pojo.vo.devicedata.PropertyDataVO;
import com.ruoyi.web.service.devicedata.DevicePropertyService;
import com.ruoyi.web.utils.v2.property.V2DeviceProperty;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Api(value = "设备数据",tags = "设备数据")
@RestController
@RequestMapping("/device-property")
public class DevicePropertyController extends BaseController {

    @Autowired
    private DevicePropertyService devicePropertyService;

    @GetMapping("/properties/latest")
    @ApiOperation("获取指定ID设备最新数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId",value = "设备编号", required = true, paramType = "query"),
            @ApiImplicitParam(name = "startTime",value = "开始时间,格式: yyyy-MM-dd HH:mm:ss", required = true, paramType = "query"),
            @ApiImplicitParam(name = "endTime",value = "结束时间,格式: yyyy-MM-dd HH:mm:ss", required = true, paramType = "query"),
    })
    public R<List<V2DeviceProperty>> latest(@RequestParam String deviceId,
                                            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") String startTime,
                                            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") String endTime) {
        List<V2DeviceProperty> latest = devicePropertyService.latest(deviceId, startTime, endTime);
        return R.ok(latest);
    }

    @GetMapping("/properties/countData")
    @ApiOperation("查询因子的统计数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceId",value = "设备编号", required = true),
            @ApiImplicitParam(name = "factorName",value = "因子key", required = true),
    })
    public R<PropertyDataVO> countData(@RequestParam String deviceId, @RequestParam String factorName) {
        PropertyDataVO vo = devicePropertyService.countPropertyData(deviceId, factorName);
        return R.ok(vo);
    }

    @GetMapping("/properties/countRainData")
    @ApiOperation("查询降雨的统计数据")
    public R<List<DeviceFactorCountData>> countRainData(DeviceRainCountRequest request) {
        List<DeviceFactorCountData> vo = devicePropertyService.countRainData(request);
        return R.ok(vo);
    }



}
